import { createI18n } from 'vue-i18n'
import Storage from '@/utils/Storage'
import ZH from '@/i18n/zh'

// 定义语言数据
const message = {
  zh: {
    ...ZH
  }
}

// 获取当前的语言代码
const getCurrentLanguage = () => {
  // 获取浏览器中用户定义的首先语言
  const UAlang = navigator.language // zh-CN
  const langCode = UAlang.indexOf('zh') !== -1 ? 'zh' : 'zh'
  Storage.setLocal('lang', langCode)
  return langCode
}

const i18n = createI18n({
  legacy: false,
  globalInjection: true,
  locale: getCurrentLanguage() || 'zh',
  messages: message
})

export default i18n
